package org.yhx.learning.verticle.eventbus;/*
 * Copyright (C), 2024, bigmoon
 * FileName:
 * Author:   bigmoon
 * Date:     2024/9/5 11:43
 * Description: //模块目的、功能描述
 * History: //修改记录
 * &lt;author&gt;      &lt;time&gt;      &lt;version&gt;    &lt;desc&gt;
 * 修改人姓名             修改时间            版本号                  描述
 */

import io.vertx.core.AbstractVerticle;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.JsonObject;

public class HttpServer extends AbstractVerticle {


    @Override
    public void start() throws Exception {

        vertx.createHttpServer().requestHandler(request -> {

            String path = request.path();

            HttpServerResponse response = request.response();
            response
                    .putHeader("Content-Type", "text/html")
                    .putHeader("Cache-Control", "no-cache");
//                    .setChunked(true);

            if ("/".equals(path)) {
                response.end("hello sensor server");
                return;
            }

            if ("/see".equals(path)) {
                vertx.eventBus().<Double>request("sensor.average", "", reply -> {
                    if (reply.succeeded()) {
                        Double temp = reply.result().body();
                        response.end("avrage temp:" + temp);
                    }
                });
            }

        }).listen(8080);
    }
}
